package com.nlecloud.bc.controller.contract;

import com.nlecloud.bc.interceptor.AuthTokenStorage;
import com.nlecloud.bc.model.Result;
import com.nlecloud.bc.model.User;
import com.nlecloud.bc.service.contract.IUserContractService;
import org.fisco.bcos.sdk.transaction.model.exception.ContractException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author warrior
 * @description 用户合约API
 */
@RestController
public class UserContractController {

    @Autowired
    private IUserContractService userContractService;

    /**
     * 版权交易
     * @param uuid 版权信息ID
     * @return
     */
    @PostMapping("contract/transfer")
    public Result transfer(@RequestParam("uuid") String uuid) throws ContractException {
        User user = AuthTokenStorage.getUser();
        String userId = user.getId();
        boolean success = userContractService.transfer(uuid,userId);
        if (!success) {
            return Result.failed("版权交易失败");
        }
        return Result.succeed("版权交易成功");
    }
}
